package com.himore.api.web.service.impl;
import java.util.List;

import com.himore.api.common.core.domain.entity.SysUser;
import com.himore.api.common.core.text.Convert;
import com.himore.api.common.utils.DateUtils;
import com.himore.api.common.utils.SecurityUtils;
import com.himore.api.system.mapper.SysUserMapper;
import com.himore.api.web.mapper.TSysCommentMapper;
import com.himore.api.web.mapper.TSysInvitationMapper;
import com.himore.api.web.model.TSysComment;
import com.himore.api.web.model.TSysCommentVO;
import com.himore.api.web.model.TSysInvitation;
import com.himore.api.web.service.ITSysCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;



/**
 * 评论信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2021-05-12
 */
@Service
public class TSysCommentServiceImpl implements ITSysCommentService
{
    @Autowired
    private TSysCommentMapper tSysCommentMapper;

    @Autowired
    private TSysInvitationMapper tSysInvitationMapper;

    @Autowired
    private SysUserMapper sysUserMapper;

    /**
     * 查询评论信息
     * 
     * @param commentId 评论信息ID
     * @return 评论信息
     */
    @Override
    public TSysComment selectTSysCommentById(Long commentId)
    {
        return tSysCommentMapper.selectTSysCommentById(commentId);
    }

    /**
     * 查询评论信息列表
     * 
     * @param tSysComment 评论信息
     * @return 评论信息
     */
    @Override
    public List<TSysCommentVO> selectTSysCommentList(TSysComment tSysComment)
    {
        return tSysCommentMapper.selectTSysCommentList(tSysComment);
    }

    /**
     * 新增评论信息
     * 
     * @param tSysComment 评论信息
     * @return 结果
     */
    @Override
    public TSysComment insertTSysComment(TSysComment tSysComment)
    {
        SysUser currUser = SecurityUtils.getLoginUser().getUser();
        tSysComment.setCreateTime(DateUtils.getNowDate());
        tSysComment.setUserId(currUser.getUserId());
        tSysComment.setHaveRead(0);;
        TSysInvitation invitation = new TSysInvitation();
        invitation.setInvitationId(tSysComment.getInvitationId());
        invitation.setCommentCount(1);
        tSysInvitationMapper.updateCommentCount(invitation);
        int  id=        tSysCommentMapper.insertTSysComment(tSysComment);
        SysUser user = sysUserMapper.selectUserById(tSysComment.getUserId());
        tSysComment.setProfilePic(user.getAvatar());
        tSysComment.setNickName(user.getNickName());
        return tSysComment;
    }

    /**
     * 修改评论信息
     * 
     * @param tSysComment 评论信息
     * @return 结果
     */
    @Override
    public int updateTSysComment(TSysComment tSysComment)
    {
        tSysComment.setUpdateTime(DateUtils.getNowDate());
        return tSysCommentMapper.updateTSysComment(tSysComment);
    }

    /**
     * 删除评论信息对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteTSysCommentByIds(String ids)
    {
        return tSysCommentMapper.deleteTSysCommentByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除评论信息信息
     * 
     * @param commentId 评论信息ID
     * @return 结果
     */
    @Override
    public int deleteTSysCommentById(Long commentId)
    {
        return tSysCommentMapper.deleteTSysCommentById(commentId);
    }

}
